<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\api\validate;

use app\common\library\Sms;
use app\common\model\CaptainApplication;
use think\Validate;

class Group extends Validate
{
    protected $name;

    protected $idcard;

    /**
     * 验证规则
     */
    protected $rule = [
        'title' => 'require|length:1,150',
        'start_date'   => 'require|date',
        'end_date'   => 'require|date|gt:start_date',
        'number_people'   => 'require|integer',
        'describe'   => 'require',
        //'address'   => 'require',
        'is_store'  => 'require|in:0,1|checkOther',
        'image'  => 'require',
        /*'long'   => 'require|number',
        'lat'   => 'require|number',*/
    ];

    /**
     * 字段描述
     */
    protected $field = [
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'title.require'=>'组队标题不能为空',
        'title.length'=>'组队标题字符长度为1-150个字符内',
        'start_date.require'=>'开始时间不能为空',
        'start_date.date'=>'开始时间格式不正确',
        'end_date.require'=>'结束时间不能为空',
        'end_date.date'=>'结束时间格式不正确',
        'end_date.gt'=>'结束时间必须大于开始时间',
        'number_people.require'=>'组队人数不能为空',
        'describe.require'=>'描述不能为空',
        'image.require'=>'图片不能为空'
    ];
    public function __construct(array $rules = [], $message = [], $field = [])
    {
        parent::__construct($rules, $message, $field);
    }

    protected function checkOther($is_store,$rule,$data){
        if ($is_store){
            if ($data['store_id'] < 1){
                $this->error = '请选择门店';
                return false;
            }
        }else{
            if (empty($data['address'])){
                $this->error = '地址不能为空';
                return false;
            }

            if (empty($data['long'])){
                $this->error = '地址经度不正确';
                return false;
            }

            if (empty($data['lat'])){
                $this->error = '地址纬度不正确';
                return false;
            }
        }
        return true;
    }



    protected function setFiled($key,$value)
    {
        $this->$key = $value;
    }

    public function getFiled($key)
    {
        return $this->$key;
    }
}
